# import time
#
# from selenium import webdriver
# from selenium.common import NoSuchElementException
# from selenium.webdriver.chrome.service import Service
# from selenium.webdriver.common.by import By
# from selenium.webdriver.support.ui import WebDriverWait
# from selenium.webdriver.support import expected_conditions as EC
# from selenium.webdriver.chrome.options import Options
#
# chrome_driver_path = "/usr/local/bin/chromedriver"
# # 配置 Chrome 选项
# options = Options()
# options.add_argument("--disable-blink-features=AutomationControlled")
#
# driver = webdriver.Chrome(service=Service(executable_path=chrome_driver_path), options=options)
#
# # 初始化WebDriver（假设使用Chrome）
#
# # 打开目标网页
# url = 'https://www.sanzhiyang.cn/home/news'  # 替换为实际的URL
# driver.get(url)
#
# # 查找news-container
# news_container = WebDriverWait(driver, 10).until(
#     EC.presence_of_element_located((By.CLASS_NAME, 'news-container'))
# )
#
# # 查找newest容器
# newest_container = WebDriverWait(news_container, 10).until(
#     EC.presence_of_element_located((By.CLASS_NAME, 'newest'))
# )
#
# # 查找newest容器中的所有div标签
# div_tags = newest_container.find_elements(By.TAG_NAME, 'div')
#
# # 遍历每一个div标签，提取信息
# for div in div_tags:
#     # 提取图片URL（如果有图片）
#     try:
#         img_tag = div.find_element(By.TAG_NAME, 'img')
#         img_url = img_tag.get_attribute('src')
#         # 点击图片
#         img_tag.click()
#         print(f'Clicked on image with URL: {img_url}')
#
#         # 等待新窗口打开
#         WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(2))
#
#         # 切换到新窗口
#         new_window = driver.window_handles[1]
#         driver.switch_to.window(new_window)
#         # 获取当前页面的基础信息
#         detail = driver.find_element(By.CLASS_NAME, 'detail w-1200')
#         title = detail.find_element(By.TAG_NAME, 'detail-title')
#         time = detail.find_element(By.TAG_NAME, 'detail-time')
#         content = detail.find_element(By.TAG_NAME, 'detail-content')
#         print(f'title: {title}', f'content: {content}', f'time: {time}')
#     except NoSuchElementException:
#         img_url = None
#
#     # 提取标题（如果有标题）
#     try:
#         title_h4 = div.find_element(By.CSS_SELECTOR, '.newest-title')
#         title = title_h4.text
#     except NoSuchElementException:
#         title = None
#
#
# print(1)
#
# # 关闭浏览器
# driver.quit()
